﻿using System.Data;
using System.Data.Common;

namespace Quest.Core.DataAccess
{
    internal interface IServer
    {
        DbConnection Connection { get; set; }

        DbCommand Command { get; set; }

        DbTransaction Transaction { get; set; }

        string ConnectionString { get; set; }

        void Init(string connectionString);

        /// <summary>
        /// 增加输入参数
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dbType"></param>
        /// <param name="value"></param>
        void AddParameter(string name, DbType dbType, object value);

        /// <summary>
        /// 增加输出参数
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dbType"></param>
        /// <param name="size"></param>
        void AddOutParameter(string name, DbType dbType, int size);

        /// <summary>
        /// 增加返回参数
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dbType"></param>
        void AddReturnParameter(string name, DbType dbType);

        /// <summary>
        /// 打开连接
        /// </summary>
        void Open();

        /// <summary>
        /// 关闭连接
        /// </summary>
        void Close();

        /// <summary>
        /// 执行SQL语句，返回影响行数
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        int ExecuteNonQuery(string text, CommandType type = CommandType.Text);

        /// <summary>
        /// 返回首行首列对象
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        object ExecuteScalar(string text, CommandType type = CommandType.Text);

        /// <summary>
        /// 执行查询返回 DbDataReader
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        DbDataReader ExecuteReader(string text, CommandType type = CommandType.Text);

        /// <summary>
        /// 执行查询返回DataSet
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        DataSet ExecuteDataSet(string text, CommandType type = CommandType.Text);

        /// <summary>
        /// 执行查询返回DataTable
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        DataTable ExecuteDataTable(string text, CommandType type = CommandType.Text);
    }
}
